package com.example.springtrans.service;

import com.example.springtrans.mapper.LogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Service

public class LogService {
    @Autowired
    private LogMapper logMapper;
    @Transactional(propagation = Propagation.REQUIRED)
    public Integer insertLog(String userName, String op){
        int result = logMapper.insertLog(userName, op);
        try {
            int a = 1 / 0;
        }catch (Exception e){
            // 回滚当前事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }

        return result;
    }
}
